package com.accenture.adf.newcodington.module20.sample;

import java.sql.Connection;
import java.sql.PreparedStatement;


public class UpdateTryIt {
	public static void main(String[] args) {
		try{
			//Obtaining a connection
			Connection con = ConnectionToDBTryIt.getConnection();
			if(con != null)
			{
			System.out.println("Connection successfully established!");
			}
			
			//Creating a PreparedStatement with a query "update Department set dept_name = 'Human Resource' where dept_id=?"
			PreparedStatement pStmt = con.prepareStatement("update Department set dept_name = 'Human Resource' where dept_id=?");
			
			//Replacing ? with actual value - D005
			pStmt.setString(1,"D005");
			
			//Executing this query using executeUpdate()
			int rows = pStmt.executeUpdate();
			
			//Print the number of rows updated
			System.out.println(rows + " record was updated");
		
			//Closing the connection
			con.close();
			
		}catch (Exception e){
			System.out.println(e.getMessage());
		}

	}
}
